import * as _ from "lodash"
import httpClient from "../httpclient"

export enum CaptchaType {
  Sms = "sms"
}

type KeyValue = { [key: string]: string }

export class Captcha {
  public type: CaptchaType = CaptchaType.Sms
  public token: string
  public code: string
  public intervals: number
  public expires: number
  public parameters: KeyValue = {}
  private created_time: string

  public get createdTime() {
    return this.created_time
  }
}

export class CaptchaServiceV1 {

  public static generateCaptcha(captcha: Captcha): Promise<Captcha> {
    return httpClient.post(`/v1/captchas`, captcha)
      .then(({ data }) => _.assign(new Captcha(), data))
  }
}
